home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / KEY.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  2KB  |  65 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 239 of 313
  3. From : Ingo Rohloff                        2:246/36.7           11 May 93  20:59
  4. To   : Spits Steven                        1:274/12.0
  5. Subj : Keypressed
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  > I've got a problem I just CAN'T solve...
  8.  
  9.  > In a PASCAL-program I want to execute a procedure every time the user
  10.  > presses a
  11.  > key... Fairly easy, right ? But here comes the problem : I want to
  12.  > repeat that
  13.  > procedure until he RELEASES that key...
  14.  
  15. The only way to do that is to hook up the int 9 (the Keyoard Int...).}
  16.  
  17. { Tested }
  18. program KEY;
  19.  
  20. uses crt,dos;
  21.  
  22. var oldint:pointer;
  23.     keydown:byte;
  24.     keys:array[0..127] of boolean;
  25.     scan,lastkey:byte;
  26.  
  27. procedure init;
  28. var i:byte;
  29. begin
  30.   clrscr;
  31.   for i:=0 to 127 do keys[i]:=false;   {No keys pressed}
  32.   keydown:=0;
  33. end;
  34.  
  35. procedure INT9; interrupt;
  36. begin
  37.   scan:=port[$60];     { Get Scancode }
  38.   if scan>$7F then     { Key released ? }
  39.   begin
  40.     if keys[scan xor $80] then dec(keydown);
  41.     keys[scan xor $80]:=false;   {Yes !}
  42.   end else
  43.   begin
  44.     if not keys[scan] then inc(keydown);
  45.     keys[scan]:=true;  {NO ! Key pressed }
  46.     lastkey:=scan;
  47.   end;
  48.   port[$20]:=$20;  { Send EndOfInterrupt to Interruptcontroller }
  49. end;
  50.  
  51. begin
  52.   init;
  53.   getintvec(9,oldint);
  54.   setintvec(9,@INT9);
  55.   repeat
  56.     if (keydown>0) and not keys[1] then
  57.     begin
  58.       repeat
  59.         sound(lastkey*30);
  60.       until keydown=0;
  61.       nosound;
  62.     end;
  63.   until keys[1];        {*** Wait for ESC pressed ***}
  64.   setintvec(9,oldint);
  65. end.